#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
void solve()
{
    int n;
    cin >> n;
    vector<int> arr(n + 10);
    int i = 0;
    int num1 = 0;
    int num2 = 0;
    for (i = 1; i <= n; i++)
    {
        cin >> arr[i];
    }
    int tag = arr[n];
    int ans = 0;
    int count = 0;
    for (i = n; i > 0; i--)
    {
        if (tag == 0)
        {
            tag = arr[i];
        }
        if (arr[i] != tag)
        {
            ans++;
            tag = 0;
            count = 0;
        }
        else
            count++;
    }
    ans += count;
    cout << ans << endl;
}
int main()
{
    ll t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}
